<!DOCTYPE html>
<html lang="en">
	<head>
		<title>three.js webgl - postprocessing smaa</title>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
		<style>
			body {
				margin: 0px;
				background-color: #000000;
				overflow: hidden;
			}
		</style>
	</head>
	<body>

		<div id="container"></div>

		<script src="../build/three.js"></script>
		<script src="js/libs/stats.min.js"></script>

		<script src="js/shaders/CopyShader.js"></script>
		<script src="js/shaders/SMAAShader.js"></script>

		<script src="js/postprocessing/EffectComposer.js"></script>
		<script src="js/postprocessing/SMAAPass.js"></script>
		<script src="js/postprocessing/RenderPass.js"></script>
		<script src="js/postprocessing/MaskPass.js"></script>
		<script src="js/postprocessing/ShaderPass.js"></script>


		<script>

			var camera, scene, renderer, composer, pass, stats;

			init();
			animate();

			function init( meshTexture ) {

				container = document.getElementById( "container" );

				renderer = new THREE.WebGLRenderer( { antialias: false } );
				renderer.setPixelRatio( window.devicePixelRatio );
				renderer.setSize( window.innerWidth, window.innerHeight );
				document.body.appendChild( renderer.domElement );

				stats = new Stats();
				container.appendChild( stats.dom );

				//

				camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 1, 1000 );
				camera.position.z = 300;

				scene = new THREE.Scene();

				var geometry = new THREE.BoxGeometry( 120, 120, 120 );
				var material = new THREE.MeshBasicMaterial( { color: 0xffffff, wireframe: true } );

				var mesh = new THREE.Mesh( geometry, material );
				mesh.position.x = - 100;
				scene.add( mesh );

				var texture = new THREE.TextureLoader().load( "textures/brick_diffuse.jpg" );
				texture.anisotropy = 4;

				var material = new THREE.MeshBasicMaterial( { map: texture } );

				var mesh = new THREE.Mesh( geometry, material );
				mesh.position.x = 100;
				scene.add( mesh );

				// postprocessing

				composer = new THREE.EffectComposer( renderer );
				composer.addPass( new THREE.RenderPass( scene, camera ) );

				pass = new THREE.SMAAPass( window.innerWidth, window.innerHeight );
				pass.renderToScreen = true;
				composer.addPass( pass );

				window.addEventListener( 'resize', onWindowResize, false );

			}

			function onWindowResize() {

				var width = window.innerWidth;
				var height = window.innerHeight;

				camera.aspect = width / height;
				camera.updateProjectionMatrix();

				renderer.setSize( width, height );

				var pixelRatio = renderer.getPixelRatio();
				var newWidth  = Math.floor( width / pixelRatio ) || 1;
				var newHeight = Math.floor( height / pixelRatio ) || 1;
				composer.setSize( newWidth, newHeight );

			}

			function animate() {

				requestAnimationFrame( animate );

				stats.begin();

				for ( var i = 0; i < scene.children.length; i ++ ) {

					var child = scene.children[ i ];

					child.rotation.x += 0.005;
					child.rotation.y += 0.01;

				}

				composer.render();

				stats.end();

			}

		</script>

	</body>
</html>
